

clear all
set more off, perm
capture log close
set maxvar 32767
global klmChinaReach2: env klmChinaReach2
global datapath "${klmChinaReach2}/Fuyao_Erlfang"
cd "$datapath\eta\maturation"


**# Cognitive

use eta_maturation_cog_mul, clear

replace eta = . if eta == -99

gen se = eta

// sort levelc2 ts_id
// gen indexc2_1= sum(!missing(levelc2)) if !missing(levelc2)
// sort ts_id
preserve
collapse eta levelc2 ts_id (semean) se, by(indexc2)
gen lb_95 = eta - 1.96*se
gen ub_95 = eta + 1.96*se

sort levelc2 ts_id
gen indexc2_1= sum(!missing(levelc2)) if !missing(levelc2)

label var eta "E({&eta})"
label var ub "95% CI"

local xlines ""
local xlabels ""

sum levelc2
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexc2_1 if levelc2==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}
	twoway connected eta indexc2_1, sort lwidth(medthin) msize(small) lpattern(dash) || line ub indexc2_1, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexc2_1, sort lcolor(gs11) lpattern(dash) lwidth(medthin) ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(medthin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title("E({&eta}) of Cognitive Tasks by Level", size(medium)) subtitle(All Tasks, size(small)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels," "tasks are arranged by order of the curriculum design.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("cog_eta", replace)
	graph export "cog_eta.pdf", replace	
restore

forval i=1/3{
	gen eta`i' = eta if abi_ct == `i'
	gen se`i' = eta`i'
}

preserve
collapse eta1 eta2 eta3 levelc2 ts_id (semean) se1 se2 se3, by(indexc2)

forval i =1/3{
gen lb`i' = eta`i' - 1.96*se`i'
gen ub`i' = eta`i' + 1.96*se`i'
}
label var eta1 "Fast"
label var eta2 "Normal"
label var eta3 "Slow"
label var ub1 "95% CI"

sort levelc2 ts_id
gen indexc2_1= sum(!missing(levelc2)) if !missing(levelc2)


local xlines ""
local xlabels ""

sum levelc2
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexc2_1 if levelc2==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

twoway line eta1 indexc2_1, sort lwidth(medthin) || line ub1 indexc2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb1 indexc2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || connected eta2 indexc2_1, sort msize(small) lwidth(medthin) || line ub2 indexc2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb2 indexc2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line eta3 indexc2_1, sort lpattern(longdash_shortdash) lwidth(medthin) || line ub3 indexc2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb3 indexc2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(medthin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title("E({&eta}) for Cognitive Tasks by Ability Group and Level", size(med)) legend(order(1 4 7 2) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("cog_abi_eta", replace)
	graph export "cog_abi_eta.pdf", replace

restore	
	

	
**# Lan

use eta_maturation_lang_mul, clear

replace eta = . if eta == -99

gen se = eta

// sort levelc2 ts_id
// gen indexc2_1= sum(!missing(levelc2)) if !missing(levelc2)
// sort ts_id
preserve
collapse eta levell ts_id (semean) se, by(indexl)
gen lb_95 = eta - 1.96*se
gen ub_95 = eta + 1.96*se

sort levell ts_id
gen indexl_1= sum(!missing(levell)) if !missing(levell)

label var eta "E({&eta})"
label var ub "95% CI"
drop if levell ==1
local xlines ""
local xlabels ""

sum levell
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexl_1 if levell==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}
	twoway connected eta indexl_1, sort lwidth(medthin) msize(small) lpattern(dash) || line ub indexl_1, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexl_1, sort lcolor(gs11) lpattern(dash) lwidth(medthin) ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(medthin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title("E({&eta}) of Language Tasks by Level", size(medium)) subtitle(All Tasks, size(small)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels," "tasks are arranged by order of the curriculum design." "All the children started from level 2 or above upon enrolling.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("lan_eta", replace)
	graph export "lan_eta.pdf", replace	
restore



forval i=1/3{
	gen eta`i' = eta if abi_lt == `i'
	gen se`i' = eta`i'
}

preserve
collapse eta1 eta2 eta3 levell ts_id (semean) se1 se2 se3, by(indexl)

forval i =1/3{
gen lb`i' = eta`i' - 1.96*se`i'
gen ub`i' = eta`i' + 1.96*se`i'
}

label var eta1 "Fast"
label var eta2 "Normal"
label var eta3 "Slow"
label var ub1 "95% CI"

sort levell ts_id
gen indexl_1= sum(!missing(levell)) if !missing(levell)

drop if levell ==1
local xlines ""
local xlabels ""

sum levell
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexl_1 if levell==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

twoway line eta1 indexl_1, sort lwidth(medthin) || line ub1 indexl_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb1 indexl_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || connected eta2 indexl_1, sort msize(small) lwidth(medthin) || line ub2 indexl_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb2 indexl_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line eta3 indexl_1, sort lpattern(longdash_shortdash) lwidth(medthin) || line ub3 indexl_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb3 indexl_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(medthin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title("E({&eta}) for Language Tasks by Ability Group and Level", size(med)) legend(order(1 4 7 2) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups." "3. All the children started from level 2 or above upon enrolling.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("lan_abi_eta", replace)
	graph export "lan_abi_eta.pdf", replace

restore	
	
**# fine


use eta_maturation_fine_mul, clear

replace eta = . if eta == -99

gen se = eta

// sort levelf2 ts_id
// gen indexf2_1= sum(!missing(levelf2)) if !missing(levelf2)
// sort ts_id
preserve
collapse eta levelf2 ts_id (semean) se, by(indexf2)
gen lb_95 = eta - 1.96*se
gen ub_95 = eta + 1.96*se

sort levelf2 ts_id
gen indexf2_1= sum(!missing(levelf2)) if !missing(levelf2)

label var eta "E({&eta})"
label var ub "95% CI"

local xlines ""
local xlabels ""

sum levelf2
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexf2_1 if levelf2==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}
	twoway connected eta indexf2_1, sort lwidth(medthin) msize(small) lpattern(dash) || line ub indexf2_1, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexf2_1, sort lcolor(gs11) lpattern(dash) lwidth(medthin) ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(medthin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title("E({&eta}) of Fine Motor Tasks by Level", size(medium)) subtitle(All Tasks, size(small)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels," "tasks are arranged by order of the curriculum design.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("fine_eta", replace)
	graph export "fine_eta.pdf", replace	
restore

forval i=1/3{
	gen eta`i' = eta if abi_ft == `i'
	gen se`i' = eta`i'
}

preserve
collapse eta1 eta2 eta3 levelf2 ts_id (semean) se1 se2 se3, by(indexf2)

forval i =1/3{
gen lb`i' = eta`i' - 1.96*se`i'
gen ub`i' = eta`i' + 1.96*se`i'
}
label var eta1 "Fast"
label var eta2 "Normal"
label var eta3 "Slow"
label var ub1 "95% CI"

sort levelf2 ts_id
gen indexf2_1= sum(!missing(levelf2)) if !missing(levelf2)


local xlines ""
local xlabels ""

sum levelf2
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexf2_1 if levelf2==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

twoway line eta1 indexf2_1, sort lwidth(medthin) || line ub1 indexf2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb1 indexf2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || connected eta2 indexf2_1, sort msize(small) lwidth(medthin) || line ub2 indexf2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb2 indexf2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line eta3 indexf2_1, sort lpattern(longdash_shortdash) lwidth(medthin) || line ub3 indexf2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) || line lb3 indexf2_1, sort lcolor(gs15) lpattern(dash) lwidth(medthin) ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(medthin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title("E({&eta}) for Fine Motor Tasks by Ability Group and Level", size(med)) legend(order(1 4 7 2) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("fine_abi_eta", replace)
	graph export "fine_abi_eta.pdf", replace

restore	
	
